﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


//sprite & sprite movement
//health, stats, attack

namespace PankowGame13
{
    public enum PlayerClass
    {
        Rogue,
        Adventurer,
        Warrior,
        Mage,
        Hunter
    }
    public enum PlayerStats
    {
        Health,
        Speed,
        Strength,
        Intelligence,
        Defense,
        Attack,
        WeaponStrength,
        TreasureFind
    }

    class Player
    {
        public Texture2D playerSprite { get; set; }
        public Rectangle playerPosition { get; set; }

        public string playersClass { get; set; }
        public PlayerClass theClass { get; set; }
        public int playerSpeed { get; set; }
        public int playerHealth { get; set; }
        public int playerMaxHealth { get; set; }
        public int playerStrength { get; set; }
        public int playerIntelligence { get; set; }
        public int playerDefense { get; set; }
        public int dungeonLevel { get; set; }
        public double weaponStrength { get; set; }
        public int attack { get; set; }
        public int playerTreasureFind { get; set; }
        public int killCount { get; set; }
        public bool isFighting { get; set; }

        public int playerTreasureAmount { get; set; }
        public Item[] playerItems { get; set; }
        public int numPotions { get; set; }

        private int floatingTextOffset { get; set; }

        bool potionKeyUp = true;

        public Player(Vector2 plPos, Vector2 plSize, ContentManager content, PlayerClass plClass)
        {
            //initialize items
            floatingTextOffset = 0;
            isFighting = false;
            playerTreasureFind = 0;
            numPotions = 1;
            playerItems = new Item[8];
            for (int i = 0; i < 8; i++)
            {
                playerItems[i] = new Item(content);
            }

            killCount = 0;
            theClass = plClass;
            playerTreasureAmount = 0;
            playerSprite = content.Load<Texture2D>(@"Adventurer Base");
            playerPosition = new Rectangle((int)plPos.X, (int)plPos.Y, (int)plSize.X, (int)plSize.Y);
            playerSpeed = 2;
            dungeonLevel = 1;
            weaponStrength = .5; //this is bareheanded
            attack = 0;
            switch (plClass)
            {
                case PlayerClass.Rogue:
                    playerMaxHealth = 90;
                    playerHealth = playerMaxHealth;
                    playerStrength = 40;
                    playerIntelligence = 60;
                    playerDefense = 38;
                    playersClass = "Rogue";
                    break;
                case PlayerClass.Adventurer:
                    playerMaxHealth = 120;
                    playerHealth = playerMaxHealth;
                    playerStrength = 60;
                    playerIntelligence = 50;
                    playerDefense = 42;
                    playersClass = "Adventurer";
                    break;
                case PlayerClass.Warrior:
                    playerMaxHealth = 150;
                    playerHealth = playerMaxHealth;
                    playerStrength = 100;
                    playerIntelligence = 30;
                    playerDefense = 50;
                    playersClass = "Warrior";
                    break;
                case PlayerClass.Mage:
                    playerMaxHealth = 80;
                    playerHealth = playerMaxHealth;
                    playerStrength = 30;
                    playerIntelligence = 100;
                    playerDefense = 30;
                    playersClass = "Mage";
                    break;
                case PlayerClass.Hunter:
                    playerMaxHealth = 90;
                    playerHealth = playerMaxHealth;
                    playerStrength = 50;
                    playerIntelligence = 40;
                    playerDefense = 42;
                    playersClass = "Hunter";
                    break;
            }
        }

        public void MonsterCombat(Enemy theEnemy, FloatingTextManager ftm, GameTime gameTime, Game1 theGame, SoundEffect combat, SoundEffect levelSound, int numEnemies)
        {
            isFighting = true;
                combat.Play();
                //calculate player attack
                //subtract from monster health
                //calculate monster attack
                //subtract from player health
                //check if dead
                Random rand = new Random();

                int pAttack = 0;

                if (this.theClass == PlayerClass.Mage)
                {
                    pAttack = (int)((this.playerIntelligence + this.dungeonLevel + rand.Next(5, 16))) - theEnemy.enemyDefense;
                    attack = pAttack;
                }
                if (this.theClass == PlayerClass.Warrior)
                {
                    pAttack = (int)((this.playerStrength + this.dungeonLevel + rand.Next(1, 11)) * weaponStrength) - theEnemy.enemyDefense;
                    attack = pAttack;
                }
                if (this.theClass == PlayerClass.Rogue)
                {
                    pAttack = (int)((this.playerStrength + this.dungeonLevel + rand.Next(6, 9)) * weaponStrength) - theEnemy.enemyDefense;
                    attack = pAttack;
                }
                if (this.theClass == PlayerClass.Adventurer)
                {
                    pAttack = (int)((this.playerStrength + this.dungeonLevel + rand.Next(1, 5) + (int)(this.playerTreasureAmount * .05)) * weaponStrength) - theEnemy.enemyDefense;
                    attack = pAttack;
                }
                if (this.theClass == PlayerClass.Hunter)
                {
                    pAttack = (int)((this.playerStrength + this.dungeonLevel + rand.Next(5, 10)) * weaponStrength) - theEnemy.enemyDefense;
                    attack = pAttack;
                }

                
                theEnemy.enemyHealth -= pAttack;
                ftm.AddFloatingText(new Vector2(theEnemy.enemyRect.X + theEnemy.enemyRect.Width/2, theEnemy.enemyRect.Y - floatingTextOffset), "-" + pAttack, Color.Green, 2500);

                System.Threading.Thread.SpinWait(100000000);

                int mAttack = theEnemy.enemyAttack-this.playerDefense;
                if (mAttack < 0)
                {
                    mAttack = 0;
                }
                this.playerHealth -= mAttack;
                ftm.AddFloatingText(new Vector2(this.playerPosition.X + this.playerPosition.Width/2, this.playerPosition.Y - floatingTextOffset), "-" + mAttack, Color.Red, 2500);

                floatingTextOffset += 12;
                
                if (theEnemy.enemyHealth < 1)
                {
                    killCount++;
                    theEnemy.status = "Dead";
                    theEnemy.isVisible = false;
                    ftm.AddFloatingText(new Vector2(theEnemy.enemyRect.X + theEnemy.enemyRect.Width/2, theEnemy.enemyRect.Y - theEnemy.enemyRect.Height/2), "Dead", Color.Green, 2500);
                    //report to screen
                    if (killCount == numEnemies)
                    {
                        levelSound.Play();
                    }
                    isFighting = false;
                    floatingTextOffset = 0;
                }
                if (this.playerHealth < 1)
                {
                    //player dies, end game
                    this.playerTreasureAmount = -1;
                    isFighting = false;
                    floatingTextOffset = 0;
                }
        }

        public void Update(KeyboardState kbs, ref Tile[,] theLevel, List<Enemy> enemies, int level, ref GameState currentGameState, ref FloatingTextManager ftm, GameTime gameTime, Game1 theGame, SoundEffect treasure, SoundEffect loot, SoundEffect combat, SoundEffect levelSound)
        {
            dungeonLevel = level;

            if (isFighting)
            {
                foreach (Enemy e in enemies)
                {
                    if (Vector2.Distance(new Vector2(playerPosition.X,playerPosition.Y), new Vector2(e.enemyRect.X, e.enemyRect.Y)) < 49)
                    {
                        MonsterCombat(e, ftm, gameTime, theGame, combat, levelSound, enemies.Count());
                    }
                }
            }

            if(kbs.IsKeyDown(Keys.W))
            {
                playerPosition = new Rectangle(playerPosition.X,playerPosition.Y - playerSpeed,playerPosition.Width,playerPosition.Height);

                foreach (Enemy e in enemies)
                {
                    if (this.playerPosition.Intersects(e.enemyRect) && e.isVisible)
                    {
                        MonsterCombat(e, ftm, gameTime, theGame, combat, levelSound, enemies.Count());
                    }
                }

                foreach (Tile t in theLevel)
                {
                    foreach (Enemy e in enemies)
                    {
                        if (t.tileRect.Intersects(this.playerPosition) || (this.playerPosition.Intersects(e.enemyRect) && e.isVisible))
                        {
                            if (!t.canPass) //you shall not pass!
                            {
                                playerPosition = new Rectangle(playerPosition.X, playerPosition.Y + playerSpeed, playerPosition.Width, playerPosition.Height);
                            }
                        }
                    }
                    if (t.GetType().ToString() == "PankowGame13.TrapTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        t.isActive = true;
                        TrapTile tempTile = (TrapTile)t;
                        if (!tempTile.hasSprung)
                        {
                            int tempDamage = tempTile.TrapDamage(dungeonLevel);
                            this.playerHealth -= tempDamage;
                            ftm.AddFloatingText(new Vector2(this.playerPosition.X + this.playerPosition.Width / 2, this.playerPosition.Y - floatingTextOffset), "-" + tempDamage, Color.Red, 2500);
                        }
                        tempTile.hasSprung = true;
                    }
                    if (t.GetType().ToString() == "PankowGame13.TreasureTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        TreasureTile tempTile = (TreasureTile)t;
                        if (tempTile.isHidden)
                        {
                            tempTile.isHidden = false;
                        }
                    }
                }
            }
            if (kbs.IsKeyDown(Keys.A))
            {
                playerPosition = new Rectangle(playerPosition.X - playerSpeed, playerPosition.Y, playerPosition.Width, playerPosition.Height);

                foreach (Enemy e in enemies)
                {
                    if (this.playerPosition.Intersects(e.enemyRect) && e.isVisible)
                    {
                        MonsterCombat(e, ftm, gameTime, theGame, combat, levelSound, enemies.Count());
                    }
                }

                
                foreach (Tile t in theLevel)
                {
                    foreach (Enemy e in enemies)
                    {
                        if (t.tileRect.Intersects(this.playerPosition) || (this.playerPosition.Intersects(e.enemyRect) && e.isVisible))
                        {
                            if (!t.canPass)
                            {
                                playerPosition = new Rectangle(playerPosition.X + playerSpeed, playerPosition.Y, playerPosition.Width, playerPosition.Height);
                            }
                        }
                    }
                    if (t.GetType().ToString() == "PankowGame13.TrapTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        t.isActive = true;
                        TrapTile tempTile = (TrapTile)t;
                        if (!tempTile.hasSprung)
                        {
                            int tempDamage = tempTile.TrapDamage(dungeonLevel);
                            this.playerHealth -= tempDamage;
                            ftm.AddFloatingText(new Vector2(this.playerPosition.X + this.playerPosition.Width / 2, this.playerPosition.Y - floatingTextOffset), "-" + tempDamage, Color.Red, 2500);
                        }
                        tempTile.hasSprung = true;
                    }
                    if (t.GetType().ToString() == "PankowGame13.TreasureTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        TreasureTile tempTile = (TreasureTile)t;
                        if (tempTile.isHidden)
                        {
                            tempTile.isHidden = false;
                        }
                    }
                }
            }
            if (kbs.IsKeyDown(Keys.S))
            {
                playerPosition = new Rectangle(playerPosition.X, playerPosition.Y + playerSpeed, playerPosition.Width, playerPosition.Height);

                foreach (Enemy e in enemies)
                {
                    if (this.playerPosition.Intersects(e.enemyRect) && e.isVisible)
                    {
                        MonsterCombat(e, ftm, gameTime, theGame, combat, levelSound, enemies.Count());
                    }
                }
              
                
                foreach (Tile t in theLevel)
                {
                    foreach (Enemy e in enemies)
                    {
                        if (t.tileRect.Intersects(this.playerPosition) || (this.playerPosition.Intersects(e.enemyRect) && e.isVisible))
                        {
                            if (!t.canPass)
                            {
                                playerPosition = new Rectangle(playerPosition.X, playerPosition.Y - playerSpeed, playerPosition.Width, playerPosition.Height);
                            }
                        }
                    }
                    if (t.GetType().ToString() == "PankowGame13.TrapTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        t.isActive = true;
                        TrapTile tempTile = (TrapTile)t;
                        if (!tempTile.hasSprung)
                        {
                            int tempDamage = tempTile.TrapDamage(dungeonLevel);
                            this.playerHealth -= tempDamage;
                            ftm.AddFloatingText(new Vector2(this.playerPosition.X + this.playerPosition.Width / 2, this.playerPosition.Y - floatingTextOffset), "-" + tempDamage, Color.Red, 2500);
                        }
                        tempTile.hasSprung = true;
                    }
                    if (t.GetType().ToString() == "PankowGame13.TreasureTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        TreasureTile tempTile = (TreasureTile)t;
                        if (tempTile.isHidden)
                        {
                            tempTile.isHidden = false;
                        }
                    }
                }

            }
            if (kbs.IsKeyDown(Keys.D))
            {
                playerPosition = new Rectangle(playerPosition.X + playerSpeed, playerPosition.Y, playerPosition.Width, playerPosition.Height);

                foreach (Enemy e in enemies)
                {
                    if (this.playerPosition.Intersects(e.enemyRect) && e.isVisible)
                    {
                        MonsterCombat(e, ftm, gameTime, theGame, combat, levelSound, enemies.Count());
                    }
                }

                
                foreach (Tile t in theLevel)
                {
                    foreach (Enemy e in enemies)
                    {
                        if (t.tileRect.Intersects(this.playerPosition) || (this.playerPosition.Intersects(e.enemyRect) && e.isVisible))
                        {
                            if (!t.canPass)
                            {
                                playerPosition = new Rectangle(playerPosition.X - playerSpeed, playerPosition.Y, playerPosition.Width, playerPosition.Height);
                            }
                        }
                    }
                    if (t.GetType().ToString() == "PankowGame13.TrapTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        t.isActive = true;
                        TrapTile tempTile = (TrapTile)t;
                        if (!tempTile.hasSprung)
                        {
                            int tempDamage = tempTile.TrapDamage(dungeonLevel);
                            this.playerHealth -= tempDamage;
                            ftm.AddFloatingText(new Vector2(this.playerPosition.X + this.playerPosition.Width / 2, this.playerPosition.Y - floatingTextOffset), "-" + tempDamage, Color.Red, 2500);
                        }
                        tempTile.hasSprung = true;
                    }
                    if (t.GetType().ToString() == "PankowGame13.TreasureTile" && t.tileRect.Intersects(this.playerPosition))
                    {
                        TreasureTile tempTile = (TreasureTile)t;
                        if (tempTile.isHidden)
                        {
                            tempTile.isHidden = false;
                        }
                    }
                }
            }

            if (kbs.IsKeyDown(Keys.Space))
            {
                foreach (Tile t in theLevel)
                {
                    if (t.tileRect.Intersects(this.playerPosition))
                    {
                        if (t.GetType().ToString() == "PankowGame13.TreasureTile")
                        {
                            TreasureTile tempTile = (TreasureTile)t;
                            if (tempTile.isLoot && !tempTile.isOpen)
                            {
                                //add to player inventory, unless potion or treasure
                                if (tempTile.lootItem.itemType == ItemTypes.Potion && !tempTile.isOpen)
                                {
                                    loot.Play();
                                    tempTile.isOpen = true;
                                    numPotions++;
                                    ftm.AddFloatingText(new Vector2(playerPosition.X + playerPosition.Width, playerPosition.Y), "+1 Potion", Color.White, 1500);
                                }
                                else if (tempTile.lootItem.itemType == ItemTypes.Treasure && !tempTile.isOpen)
                                {
                                    treasure.Play();
                                    tempTile.isOpen = true;
                                    playerTreasureAmount += tempTile.lootItem.treasureAmount;
                                    ftm.AddFloatingText(new Vector2(playerPosition.X + playerPosition.Width, playerPosition.Y), "+" + tempTile.lootItem.treasureAmount + " Treasure", Color.White, 1500);
                                }
                                else
                                {
                                    loot.Play();
                                    playerMaxHealth += tempTile.lootItem.itemBuffs[0];
                                    playerHealth += tempTile.lootItem.itemBuffs[0];
                                    playerSpeed += tempTile.lootItem.itemBuffs[1];
                                    playerStrength += tempTile.lootItem.itemBuffs[2];
                                    playerIntelligence += tempTile.lootItem.itemBuffs[3];
                                    playerDefense += tempTile.lootItem.itemBuffs[4];
                                    attack += tempTile.lootItem.itemBuffs[5];
                                    weaponStrength += tempTile.lootItem.itemBuffs[6];
                                    playerTreasureFind += tempTile.lootItem.itemBuffs[7];
                                    switch (tempTile.lootItem.itemType)
                                    {
                                        case ItemTypes.Helm:
                                            playerMaxHealth -= playerItems[0].itemBuffs[0];
                                            playerHealth -= playerItems[0].itemBuffs[0];
                                            playerSpeed -= playerItems[0].itemBuffs[1];
                                            playerStrength -= playerItems[0].itemBuffs[2];
                                            playerIntelligence -= playerItems[0].itemBuffs[3];
                                            playerDefense -= playerItems[0].itemBuffs[4];
                                            attack -= playerItems[0].itemBuffs[5];
                                            weaponStrength -= playerItems[0].itemBuffs[6];
                                            playerTreasureFind -= playerItems[0].itemBuffs[7];

                                            playerItems[0] = tempTile.lootItem;
                                            break;
                                        case ItemTypes.Chest:
                                            playerMaxHealth -= playerItems[1].itemBuffs[0];
                                            playerHealth -= playerItems[1].itemBuffs[0];
                                            playerSpeed -= playerItems[1].itemBuffs[1];
                                            playerStrength -= playerItems[1].itemBuffs[2];
                                            playerIntelligence -= playerItems[1].itemBuffs[3];
                                            playerDefense -= playerItems[1].itemBuffs[4];
                                            attack -= playerItems[1].itemBuffs[5];
                                            weaponStrength -= playerItems[1].itemBuffs[6];
                                            playerTreasureFind -= playerItems[1].itemBuffs[7];

                                            playerItems[1] = tempTile.lootItem;
                                            break;
                                        case ItemTypes.Legs:
                                            playerMaxHealth -= playerItems[2].itemBuffs[0];
                                            playerHealth -= playerItems[2].itemBuffs[0];
                                            playerSpeed -= playerItems[2].itemBuffs[1];
                                            playerStrength -= playerItems[2].itemBuffs[2];
                                            playerIntelligence -= playerItems[2].itemBuffs[3];
                                            playerDefense -= playerItems[2].itemBuffs[4];
                                            attack -= playerItems[2].itemBuffs[5];
                                            weaponStrength -= playerItems[2].itemBuffs[6];
                                            playerTreasureFind -= playerItems[2].itemBuffs[7];

                                            playerItems[2] = tempTile.lootItem;
                                            break;
                                        case ItemTypes.Boots:
                                            playerMaxHealth -= playerItems[3].itemBuffs[0];
                                            playerHealth -= playerItems[3].itemBuffs[0];
                                            playerSpeed -= playerItems[3].itemBuffs[1];
                                            playerStrength -= playerItems[3].itemBuffs[2];
                                            playerIntelligence -= playerItems[3].itemBuffs[3];
                                            playerDefense -= playerItems[3].itemBuffs[4];
                                            attack -= playerItems[3].itemBuffs[5];
                                            weaponStrength -= playerItems[3].itemBuffs[6];
                                            playerTreasureFind -= playerItems[3].itemBuffs[7];

                                            playerItems[3] = tempTile.lootItem;
                                            break;
                                        case ItemTypes.Weapon:
                                            playerMaxHealth -= playerItems[4].itemBuffs[0];
                                            playerHealth -= playerItems[4].itemBuffs[0];
                                            playerSpeed -= playerItems[4].itemBuffs[1];
                                            playerStrength -= playerItems[4].itemBuffs[2];
                                            playerIntelligence -= playerItems[4].itemBuffs[3];
                                            playerDefense -= playerItems[4].itemBuffs[4];
                                            attack -= playerItems[4].itemBuffs[5];
                                            weaponStrength -= playerItems[4].itemBuffs[6];
                                            playerTreasureFind -= playerItems[4].itemBuffs[7];

                                            playerItems[4] = tempTile.lootItem;
                                            break;
                                        case ItemTypes.Shield:
                                            playerMaxHealth -= playerItems[5].itemBuffs[0];
                                            playerHealth -= playerItems[5].itemBuffs[0];
                                            playerSpeed -= playerItems[5].itemBuffs[1];
                                            playerStrength -= playerItems[5].itemBuffs[2];
                                            playerIntelligence -= playerItems[5].itemBuffs[3];
                                            playerDefense -= playerItems[5].itemBuffs[4];
                                            attack -= playerItems[5].itemBuffs[5];
                                            weaponStrength -= playerItems[5].itemBuffs[6];
                                            playerTreasureFind -= playerItems[5].itemBuffs[7];

                                            playerItems[5] = tempTile.lootItem;
                                            break;
                                        case ItemTypes.Ring:
                                            playerMaxHealth -= playerItems[6].itemBuffs[0];
                                            playerHealth -= playerItems[6].itemBuffs[0];
                                            playerSpeed -= playerItems[6].itemBuffs[1];
                                            playerStrength -= playerItems[6].itemBuffs[2];
                                            playerIntelligence -= playerItems[6].itemBuffs[3];
                                            playerDefense -= playerItems[6].itemBuffs[4];
                                            attack -= playerItems[6].itemBuffs[5];
                                            weaponStrength -= playerItems[6].itemBuffs[6];
                                            playerTreasureFind -= playerItems[6].itemBuffs[7];

                                            playerItems[6] = tempTile.lootItem;
                                            break;
                                        case ItemTypes.Necklace:
                                            playerMaxHealth -= playerItems[7].itemBuffs[0];
                                            playerHealth -= playerItems[7].itemBuffs[0];
                                            playerSpeed -= playerItems[7].itemBuffs[1];
                                            playerStrength -= playerItems[7].itemBuffs[2];
                                            playerIntelligence -= playerItems[7].itemBuffs[3];
                                            playerDefense -= playerItems[7].itemBuffs[4];
                                            attack -= playerItems[7].itemBuffs[5];
                                            weaponStrength -= playerItems[7].itemBuffs[6];
                                            playerTreasureFind -= playerItems[7].itemBuffs[7];

                                            playerItems[7] = tempTile.lootItem;
                                            break;
                                    }
                                    ftm.AddFloatingText(new Vector2(playerPosition.X + playerPosition.Width, playerPosition.Y), tempTile.lootItem.itemName , Color.White, 1500);
                                }
                                t.isOpen = true;
                            }
                            else if(!tempTile.isLoot && !tempTile.isOpen) 
                            {
                                treasure.Play();
                                tempTile.isActive = true;
                                tempTile.isOpen = true;
                                int amountOfTreasure = tempTile.treasureAmount;
                                playerTreasureAmount += amountOfTreasure;
                                ftm.AddFloatingText(new Vector2(playerPosition.X + playerPosition.Width, playerPosition.Y), "+" + amountOfTreasure + " Treasure", Color.White, 1500);
                            }
                        }
                        if (t.GetType().ToString() == "PankowGame13.LadderTile")
                        {
                            LadderTile tempTile = (LadderTile)t;
                            
                            //take out later when monsters active
                            //tempTile.isActive = true;
                            

                            if (tempTile.isDown)
                            {
                                //go to next level
                                
                                if (killCount == enemies.Count())
                                {
                                    currentGameState = GameState.ChangeLevel;
                                    killCount = 0;
                                }
                                else
                                {
                                    //this.playersClass = "Locked!";
                                }
                            }
                            if (!tempTile.isDown)
                            {
                                if (killCount == enemies.Count())
                                {
                                    playerTreasureAmount += numPotions * 25;
                                    foreach (Item i in playerItems)
                                    {
                                        if (i.itemType != ItemTypes.Empty && !i.isMerchantItem)
                                        {
                                            switch (i.itemType)
                                            {
                                                case ItemTypes.Helm:
                                                    playerTreasureAmount += 200 * i.itemLevel;
                                                    break;
                                                case ItemTypes.Chest:
                                                    playerTreasureAmount += 200 * i.itemLevel;
                                                    break;
                                                case ItemTypes.Legs:
                                                    playerTreasureAmount += 200 * i.itemLevel;
                                                    break;
                                                case ItemTypes.Boots:
                                                    playerTreasureAmount += 200 * i.itemLevel;
                                                    break;
                                                case ItemTypes.Shield:
                                                    playerTreasureAmount += 200 * i.itemLevel;
                                                    break;
                                                case ItemTypes.Weapon:
                                                    playerTreasureAmount += 300 * i.itemLevel;
                                                    break;
                                                case ItemTypes.Ring:
                                                    playerTreasureAmount += 400 * i.itemLevel;
                                                    break;
                                                case ItemTypes.Necklace:
                                                    playerTreasureAmount += 400 * i.itemLevel;
                                                    break;
                                            }
                                        }
                                    }

                                    currentGameState = GameState.GameOver;
                                    //end the game
                                    //this.playersClass = "Up";
                                }
                                else
                                {
                                    //this.playersClass = "Locked!";
                                }
                            }
                        }
                    }
                }
            }
            if (kbs.IsKeyDown(Keys.Q) && potionKeyUp)
            {
                if (numPotions > 0)
                {
                    //give benefit
                    Random rand = new Random();
                    int chance = rand.Next(1, 101);
                    int healthLost = playerMaxHealth - playerHealth;

                    if (healthLost == 1)
                    {
                        playerHealth++;
                    }

                    if (chance <= 60) //half  health back
                    {
                        playerHealth += (int)(healthLost * .5);
                    }
                    if (chance > 60 && chance <= 90) //75% health back
                    {
                        playerHealth += (int)(healthLost * .75);
                    }
                    if (chance > 90 && chance <= 99) //90% health back
                    {
                        playerHealth += (int)(healthLost * .9);
                    }
                    if (chance == 100)
                    {
                        playerHealth = 1;
                    }

                    numPotions--;
                }
                
                potionKeyUp = false;
            }
            if (kbs.IsKeyUp(Keys.Q))
            {
                potionKeyUp = true;
            }

            //Change the ladder sprite if all enemies are down
            if (killCount == enemies.Count())
            {
                foreach (Tile t in theLevel)
                {
                    if (t.GetType().ToString() == "PankowGame13.LadderTile")
                    {
                        LadderTile lt = (LadderTile)t;
                        lt.isActive = true;
                    }
                }
            }
        }
    }
}
